{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <select name="status">
                                <option value="">订单状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>待发货</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>待收货</option>
                                <option value="3" {if !empty(input('get.status')) &&
                                    input('get.status')==3}selected{/if}>已完成</option>
                                <option value="4" {if !empty(input('get.status')) &&
                                    input('get.status')==4}selected{/if}>已取消</option>
                            </select> </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="ordersn" placeholder="订单编号" value="{:input('get.ordersn')}"
                                autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">搜索</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    共有数据：<strong id="count">{$list->total()}</strong> 条
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>订单号</th>
                                <th>用户ID</th>
                                <th>姓名|联系方式</th>
                                <th>省市区</th>
                                <th>具体地址</th>
                                <th>总积分</th>
                                <th>买家备注</th>
                                <th>状态</th>
                                <th>下单时间</th>
                                <th>物流信息</th>
                                <th>订单商品</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $list as $v}
                            <tr>
                                <td>{$v.id|default='0'}</td>
                                <td>{$v.ordersn|default='0'}</td>
                                <td>用户ID：{$v.user_id|default='0'}</td>
                                <td>联系人姓名：{$v.name|default='0'}<br />联系人手机：{$v.mobile|default='无'}</td>
                                <td>{$v.province_text|default=''}{$v.city_text|default=''}{$v.area_text|default=''}</td>
                                <td>{$v.address|default=''}</td>
                                <td>{$v.total|default='0'}</td>
                                <td>{$v.info|default='无'}</td>
                                <td>
                                    {if $v.status == 1}
                                    <button type="button" class="layui-btn layui-btn-sm  layui-btn">待发货</button>
                                    {elseif $v.status == 2}
                                    <button type="button" class="layui-btn layui-btn-sm  layui-btn">待收货</button>
                                    {elseif $v.status == 3}
                                    <button type="button" class="layui-btn layui-btn-sm  layui-btn">已完成</button>
                                    {else}
                                    <button type="button" class="layui-btn layui-btn-sm  layui-btn">取消</button>
                                    {/if}
                                </td>
                                <td>{$v.created|default=''}</td>
                                <td>物流编号{$v.postalcode|default=''}<br />物流名称：{$v.postalname|default=''}</td>
                                <td>
                                    <a title="查看" onclick="data_edit('查看','/shop/ordergoods?id={$v.id}')"
                                        href="javascript:;" class="layui-btn">
                                        查看
                                    </a>
                                </td>
                                <td class="td-manage">
                                    {if $v.status == 1}
                                    <button
                                        onclick="orderstr('请填写发货信息','/shop/orderstr','{$v.id}',2,'{$v.postalname|default=''}','{$v.postalcode|default=''}')"
                                        type="button" class="layui-btn layui-btn-normal">发货</button>
                                    <button onclick="orderstr('确定要取消订单吗？取消后，积分原路返回','/shop/orderstr','{$v.id}',4)"
                                        type="button" class="layui-btn layui-btn-danger">取消</button>
                                    {elseif $v.status == 2}
                                    <button
                                        onclick="orderstr('请填写发货信息','/shop/orderstr','{$v.id}',2,'{$v.postalname|default=''}','{$v.postalcode|default=''}')"
                                        type="button" class="layui-btn layui-btn-normal">更改发货信息</button>
                                    <button onclick="orderstr('确定要取消订单吗？取消后，积分原路返回','/shop/orderstr','{$v.id}',3)"
                                        type="button" class="layui-btn layui-btn-danger">完成</button>
                                    {elseif $v.status == 3}
                                    <button type="button"
                                        class="layui-btn-normal layui-btn-sm  layui-btn">订单已完成</button>

                                    {else}
                                    <button type="button" class="layui-btn layui-btn-sm  layui-btn">订单已取消</button>
                                    {/if}
                                </td>

                            </tr>
                            {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$list->render()|raw}
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['upload', 'form'], function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: 'users_top'
            , accept: 'file'
            , exts: 'xls|csv'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.status > 0) {
                    return layer.msg(res.msg);
                }
                //上传成功
                return layer.msg(res.msg);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
    function showimg(imgs) {
        console.log(imgs);
        layer.open({
            type: 1,
            title: false,
            shadeClose: true,
            skin: 'layui-layer-nobg', //没有背景色
            content: "<img src='" + imgs + "' style='width:100%;height: 100%;'>"
        });
    }
    function orderstr(title, url, id, status, name, code) {
        if (status == 2) {
            layer.open({
                title: title,
                type: 1,
                area: ['500px', '300px'],
                btn: ['提交', '取消'],
                content: '<table class="layui-table">\
                <colgroup><col width="50"> <col width="200"></colgroup>\
                <thead><tr><th>名称</th><th>内容</th></tr></thead>\
                <tbody><tr><td>物流名称</td><td><input id="trackname" value="'+ name + '" type="text" placeholder="请输入物流名称"  class="layui-input"/></td></tr>\
                <tr><td>物流编码</td><td><input id="tracknum" value="'+ code + '" type="text" placeholder="请输入物流编码"  class="layui-input"/></td></tr>\
                </tbody></table>',
                yes: function (index) {
                    var tracknum = $('#tracknum').val();
                    var trackname = $('#trackname').val();
                    if (!tracknum || !trackname) {
                        layer.msg('物流编码和物流名称不能为空');
                        return;
                    }
                    $.post(url, { id: id, postalcode: tracknum, postalname: trackname, status: status }, function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg);
                            layer.close(index);
                            return;
                        } else {
                            layer.msg(res.msg);
                            return;
                        }
                    });
                }
            });
        } else {
            layer.confirm(title, { title: '请谨慎操作' }, function (index) {
                $.post(url, { id: id, status: status }, function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, { icon: 1, time: 1000 });
                        location.replace(location.href);
                    } else {
                        layer.msg(data.msg, { icon: 2, time: 1000 });
                    }
                });
            });
        }
    }
</script>
{include file="public/footer"}